package com.movie.playvideos.fragment;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.movie.playvideos.R;
import com.movie.playvideos.R.id;
import com.movie.playvideos.R.layout;
import com.movie.playvideos.adapter.CustomMenuAdapter;
import com.movie.playvideos.model.Category;

public class MenuFragment extends Fragment implements OnItemClickListener {

	private List<Category> mListCategory;
	private CustomMenuAdapter mAdapter;
	private ListView mListMenu;

	private ListSelectionListener mListener;
	
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.list_slidemenu, null);
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		
		try {
			mListener = (ListSelectionListener) activity;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		mListCategory = new ArrayList<Category>();
		// phim bo
		mListCategory.add(new Category(R.drawable.icon_phim_bo, getString(R.string.menu_fragment_phimbo)));
		mListCategory.add(new Category(R.drawable.icon_phong_su, getString(R.string.menu_fragment_phongsu)));
		mListCategory.add(new Category(R.drawable.icon_van_nghe, getString(R.string.menu_fragment_vannghe)));
		mListCategory.add(new Category(R.drawable.icon_nguoi_viet_tren_dat_my,
				getString(R.string.menu_fragment_nguoiviettrendatmy)));
		mListCategory.add(new Category(R.drawable.icon_bep_vui, getString(R.string.menu_fragment_bepvui)));
		
		mListCategory.add(new Category(R.drawable.icon_dong_thoi_gian,
				getString(R.string.menu_fragment_dongthoigian)));
		mListCategory.add(new Category(R.drawable.icon_weekly_style,
				"Weekly Style"));
		mListCategory.add(new Category(R.drawable.icon_mo_mang_kien_thuc,
				getString(R.string.menu_fragment_momangkienthuc)));
		mListCategory.add(new Category(R.drawable.icon_diem_phim, getString(R.string.menu_fragment_diemphim)));

		mAdapter = new CustomMenuAdapter(getActivity(), R.layout.row,
				mListCategory);
		
		mListMenu = (ListView) getView().findViewById(R.id.listMenu);
		mListMenu.setAdapter(mAdapter);
		mAdapter.notifyDataSetChanged();
		
		mListMenu.setOnItemClickListener(this);

	}

	@Override
	public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
		Log.d("Thinhdt", "Menu Fragment onItemClick");
		mListener.onListSelection(position);
	}

	
	public interface ListSelectionListener {
		public void onListSelection(int position);
	}
}
